package zmee.common.allenum;

import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import org.apache.commons.lang.StringUtils;

/**
 * @author yss
 * @createTime 2022-12-01 15:35
 * @description OA审批流程返回结果
 */
public enum OaAuditFlowResultEnum {
    SUCCESS("0","创建流程成功"),
    FAIL("-1","创建流程失败"),
    FAIL_PERMISSION("-2","没有创建权限"),
    FAIL_CREATE_FLOW("-3","创建流程失败"),
    FAIL_FIELDORTABLE("-4","字段或表名不正确"),
    FAIL_UPDATELEVEL("-5","更新流程级别失败"),
    FAIL_CREATE_STAYTASK("-6","无法创建流程待办任务"),
    FAIL_NEXT_NOTE("-7","流程下一节点出错，请检查流程的配置，在OA中发起流程进行测试"),
    FAIL_AUTO_ASSIGN("-8","流程节点自动赋值操作错误")
    ;

    private static Log logger = LogFactory.getLog(OaAuditFlowResultEnum.class);
    OaAuditFlowResultEnum(String code,String msg){
        this.code = code;
        this.msg = msg;
    }

    private String code;
    private String msg;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    /**
     * 根据code获取返回信息
     * @param code
     * @return
     */
    public static String getMag(String code){
        logger.info(String.format("getMag工作流程处理结果为：%s",code));
        if(!StringUtils.isEmpty(code)){
            OaAuditFlowResultEnum[] values = values();
            for (OaAuditFlowResultEnum oaAuditFlowResultEnum : values) {
                if (code.equals(oaAuditFlowResultEnum.getCode())) {
                    return oaAuditFlowResultEnum.getMsg();
                }
            }
        }else {
            return OaAuditFlowResultEnum.FAIL.msg;
        }
        return OaAuditFlowResultEnum.SUCCESS.msg;
    }
}
